package com.itheima.juc23.question3;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author li
 */
public class MyRunnable implements Runnable {
    private final AtomicInteger currentNumber;
    private final int maxNumber;

    public MyRunnable(AtomicInteger currentNumber, int maxNumber) {
        this.currentNumber = currentNumber;
        this.maxNumber = maxNumber;
    }

    @Override
    public void run() {
        while (true) {
            int number = currentNumber.getAndIncrement();
            if (number > maxNumber) {
                break;
            }
            if ((number & 1) != 0) {
                System.out.println(Thread.currentThread().getName() + "输出奇数：" + number);
            }
        }
    }
}
